package com.sjtu.vfact.visualization.base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.sjtu.vfact.interfaces.Clusterable;
import com.sjtu.vfact.interfaces.Drawable;

public abstract class VfactVertex implements Drawable, Clusterable{
	
	protected List<String> terms;
	
	public VfactVertex(String[] terms){
		this.terms = Arrays.asList(terms);
	}
	
	public VfactVertex(List<String> terms){
		this.terms = terms;
	}

	public List<String> getTerms(){
		return this.terms;
	}
	
	@Override
	public int getSize(){
		return this.terms.size();
	}
	
	public boolean isEmpty(){
		return this.terms.isEmpty();
	}
	
	public boolean contains(String term){	
		if(terms.contains(term)){
			return true;
		}
		return false;
	}
	
	/**
	 * check whether this termset is a subset of "Superset" parameter
	 * @param superset
	 * @return
	 */
	@Override
	public boolean isSubsetOf(VfactVertex superset){
		for(String term : terms){
			if(!(superset.contains(term))){
				return false;
			}
		}
		return true;
	}
	
	@Override
	public List<String> getSimilarTerms(VfactVertex vertex){
		List<String> list = new ArrayList<String>();
		for(String ts : terms){
			if(vertex.contains(ts)){
				list.add(ts);
			}
		}
		
		return list;
	}
	
}
